package td3.view;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JTabbedPane;

import td3.model.AppModel;

public class ContactView extends JTabbedPane {

	private static final long serialVersionUID = -5885621388543616583L;
	private ContactTextPane contactTextPane;

	private ContactEditPane contactEditPane;

	public ContactView(AppModel appModel) {
		super();
		contactTextPane = new ContactTextPane(appModel);
		contactEditPane = new ContactEditPane(appModel);

		this.addTab("XML", contactTextPane);
		this.addTab("Contact", contactEditPane);

		appModel.addPropertyChangeListener(new PropertyChangeListener() {

			@Override
			public void propertyChange(PropertyChangeEvent event) {
				if (event.getPropertyName().equals(
						AppModel.Property.CONTACT_TREE_MODEL.name())) {
					setSelectedIndex(indexOfComponent(contactTextPane));
				} else if (event.getPropertyName().equals(
						AppModel.Property.CURRENT_CONTACT.name())) {
					if (event.getNewValue() != null) {
						setSelectedIndex(indexOfComponent(contactEditPane));
					}
				}
			}
		});
	}

	public ContactTextPane getContactTextPane() {
		return contactTextPane;
	}

	public void setContactTextPane(ContactTextPane contactTextPane) {
		this.contactTextPane = contactTextPane;
	}

	public ContactEditPane getContactEditPane() {
		return contactEditPane;
	}

	public void setContactEditPane(ContactEditPane contactEditPane) {
		this.contactEditPane = contactEditPane;
	}

}
